package com.fellansoft.moviescollection.activities;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.*;
import com.fellansoft.moviescollection.R;
import com.fellansoft.moviescollection.activities.ViewMovie;
import com.fellansoft.moviescollection.gui.ImageAdapterControlGrid;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Naty    ->Naty
 * Date: 6/14/12
 * Time: 9:50 PM
 * To change this template use File | Settings | File Templates.
 */
public class ViewPictures extends Activity {
    /* *
     * Grid view for pictures
     */
    private GridView gridView;
    /* *
     * List with URIs to be loaded into the grid view
     */
    public static List<Uri> uriList;
    /**
     * Constant for selection a picture
     */
    private final int SELECT_PHOTO = 666;
    /**
     * Image adapter for the content of the grid
     */
    private ImageAdapterControlGrid imageAdapter;
    /**
     * View Holder for the gird view containg an image
     */
    static class ViewHolder {
        ImageView pictureImageView;
    }

    /**
     * Going back to the previous activity
     */
     private Button back;
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setTheme(android.R.style.Theme_Holo);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.viewpictures);
        uriList= ViewMovie.m.getPhotos() ;
        if(uriList==null)
            uriList=new ArrayList<Uri>();
        gridView = (GridView) findViewById(R.id.photoGridView2);
        imageAdapter = new ImageAdapterControlGrid(this, uriList);
        gridView.setAdapter(imageAdapter);
        gridView.setOnItemClickListener(itemClickListener);
        back=(Button)findViewById(R.id.backButton);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }
    private AdapterView.OnItemClickListener itemClickListener = new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(uriList.get(position), "image/*");
            startActivity(intent);
        }
    };


}
